﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using groupAnalyzer.Observers;

namespace groupAnalyzer
{
    /// <summary>
    /// Interaction logic for settingsWindow.xaml
    /// </summary>
    public partial class SettingsWindow : Window
    {
        private ViewFactory viewFactory;
        private Observer observer;

        public SettingsWindow(ViewFactory viewFactory, Observer observer)
        {
            this.viewFactory = viewFactory;
            this.observer = observer;

            
            InitializeComponent();
            this.refreshBinding();
//            this.kerberosAuth_Checked(null, null);
        }

        private void refreshBinding()
        {
            this.savePassword.DataContext = this.ldapURL.DataContext = this.kerberosAuth.DataContext = this.baseDN.DataContext = this.username.DataContext = this.password.DataContext = this.viewFactory.Settings;
        }

        private void kerberosAuth_Checked(object sender, RoutedEventArgs e)
        {
           
        }

        public static void init(ViewFactory viewFactory, Observer observer)
        {
            SettingsWindow settingsWindow = new SettingsWindow(viewFactory, observer);
            settingsWindow.ShowDialog();
        }

        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            this.observer.notifiy(Messages.saveSettings, null);
            this.Close();
        }

        private void cancelClick(object sender, RoutedEventArgs e)
        {
            this.observer.notifiy(Messages.loadSettings, null);
            this.Close();
        }

        private void enableDisable(object sender, RoutedEventArgs e)
        {
            this.password.IsEnabled = this.savePassword.IsChecked.Equals(true) && this.kerberosAuth.IsChecked.Equals(false);
          
            this.savePassword.IsEnabled = this.usernameLabel.IsEnabled = this.username.IsEnabled = !(bool)this.kerberosAuth.IsChecked;
        }
    }
}
